import binascii
from io import BytesIO

import requests
from PIL import Image
import base64
import pytesseract
import warnings


from seleniumbase import BaseCase

import time
from MyTools.myutils import TestUtils

class MytestClass(TestUtils):



    def test_shouqian(self):
        self.open("http://10.0.0.75:81/index")
        try:
            cookie_str = 'rememberMe=true; sidebarStatus=0; Admin-Expires-In=1440; Library-Admin-Token=efc23d1e-4231-4e4c-a4bc-bd9580fca98a; Library-Admin-Expires-In=1440; username=%E8%BF%9E%E4%B8%B0; password=VAPJ0uSrSIjy1V5JRVyNiMGVLvKsAGSoxV2+YSSUGxhSYlEK0Y6EiKi0DxzOkizVwaNQMOO3+mVBXAHd3uK3iw==; integrated-platform-Token=9ad044c2-61e2-430f-99a1-1de0364ebc92; SECKEY_ABVK=YCX40vixPI/X7o9JGy8lc8lMVOlhXnb/cTRoC1qqAlw%3D; BMAP_SECKEY=vrOdL9oVxEd9l5LULeSN3PD-TMrb_qn7TIRu_NBXXvzn25TfkuaCCf2C5HLYkaxcG7IkZs5ZasR8X9WmoYje4JnsUcsIL-aq5dmriMN-jz5S9c50hHeF8jXQ8QDbg9TQzRPRuVmOA18cK9jXumevEBFc7224mYlQ0vwYwb25cchNYX7zkX-ZRc1KhjNFT0no'
            self.cookie_adder(cookie_str)
            self.open("http://10.0.0.75:81/index")
            while True:
                #############################  基础信息  ##########################################
                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(1)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(2)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(3)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(4)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(5)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(6)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(7)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(8)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(9)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(10)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(11)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(12)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(13)')
                self.check_status(self)

                self.click_when_visible('.el-tooltip.iconfont.item.svg-icon.applicate-class')
                self.click_when_visible('#app > div > div.app-wrapper__container.ly-flex-1 > div.s-side-menu-content > div.applicate-drawer > div > div > div > section > div > div.container > div:nth-child(15) > div > div.app-menu > div:nth-child(1) > div.wrap-item > div:nth-child(14)')
                self.check_status(self)

                ##############################  业务设置  ##########################################




                if self.get_current_url() != 'http://10.0.0.75:81':  # 变更这里的 URL 为你希望跳转的页面
                    print("测试完成")
                    break


        except Exception as e:
            print(f"抱歉，出现错误：{str(e)}")

    # def test_shouqian(self):
    #     self.open("http://10.0.0.75:811/index")
    #     try:
    #         # 添加 cookie
    #         self.driver.add_cookie({'name': 'rememberMe', 'value': 'true'})
    #         self.driver.add_cookie({'name': 'sidebarStatus', 'value': '0'})
    #         self.driver.add_cookie({'name': 'Admin-Expires-In', 'value': '1440'})
    #         self.driver.add_cookie({'name': 'Library-Admin-Token', 'value': 'efc23d1e-4231-4e4c-a4bc-bd9580fca98a'})
    #         self.driver.add_cookie({'name': 'Library-Admin-Expires-In', 'value': '1440'})
    #         self.driver.add_cookie({'name': 'username', 'value': '%E8%BF%9E%E4%B8%B0'})
    #         self.driver.add_cookie({'name': 'password', 'value': 'VAPJ0uSrSIjy1V5JRVyNiMGVLvKsAGSoxV2+YSSUGxhSYlEK0Y6EiKi0DxzOkizVwaNQMOO3+mVBXAHd3uK3iw=='})
    #         self.driver.add_cookie({'name': 'integrated-platform-Token', 'value': '9ad044c2-61e2-430f-99a1-1de0364ebc92'})
    #         self.driver.add_cookie({'name': 'SECKEY_ABVK', 'value': 'YCX40vixPI/X7o9JGy8lc8lMVOlhXnb/cTRoC1qqAlw%3D'})
    #         self.driver.add_cookie({'name': 'BMAP_SECKEY', 'value': 'vrOdL9oVxEd9l5LULeSN3PD-TMrb_qn7TIRu_NBXXvzn25TfkuaCCf2C5HLYkaxcG7IkZs5ZasR8X9WmoYje4JnsUcsIL-aq5dmriMN-jz5S9c50hHeF8jXQ8QDbg9TQzRPRuVmOA18cK9jXumevEBFc7224mYlQ0vwYwb25cchNYX7zkX-ZRc1KhjNFT0no'})
    #
    #         # 刷新页面以使 cookie 生效
    #         self.open("http://10.0.0.75:811/index")
    #     except Exception as e:
    #         print(f"抱歉，出现错误：{str(e)}")


        # @staticmethod   # 静态方法
        # def ocr(img_path):
        #     image = Image.open(img_path)
        #     text = pytesseract.image_to_string(image)
        #     return text

        #识别验证码
        # element = self.find_element('.login-code img')
        # img_src = element.get_attribute('src')
        # print(element)
        # print(img_src)
        # try:
        #     img_data = base64.b64decode(img_src.split(',')[1])
        #     img = Image.open(BytesIO(img_data))
        #
        #     # 使用 tesseract 识别图像中的文本
        #     code = pytesseract.image_to_string(img)
        #     print(code)
        # except (IndexError, binascii.Error, Exception) as e:
        #     print(f"抱歉，处理图像时出现错误：{str(e)}")


